package pl.plesken.net;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class JWGet {

	
	public void downloadFile(String link, String OutFile) throws IOException {

		URL url = new URL(link);
		URLConnection request = url.openConnection();
		request.connect();
			
        String fileType = request.getContentType();
        
        if (fileType != null) {
            byte[] buffer = new byte[4 * 1024];
            int read;

            FileOutputStream out = new FileOutputStream(OutFile);
            InputStream in = request.getInputStream();

            while ((read = in.read(buffer)) > 0) {
                    out.write(buffer, 0, read);
            }

            out.close();
            in.close();

        }
	}

}
